package com.bdqn.schoolcms.controller;


import com.bdqn.schoolcms.aspectj.annotation.Log;
import com.bdqn.schoolcms.aspectj.enums.BusinessType;
import com.bdqn.schoolcms.dto.ClassDto;
import com.bdqn.schoolcms.service.SysClassService;
import com.bdqn.schoolcms.utils.ShiroSecurityUtils;
import com.bdqn.schoolcms.vo.DataGridView;
import com.bdqn.schoolcms.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
 * @Auther: yjw
 * @Description:班级
 */
@RestController
@RequestMapping("system/class")
public class ClassController {

    @Autowired
    private SysClassService classService;

    /**
     * 分页查询
     */
    @GetMapping("listClassForPage")
    public R listClassForPage(ClassDto classDto){
        DataGridView gridView = this.classService.listPage(classDto);
        return R.success("查询成功",gridView.getData(),gridView.getTotal());
    }
    /**
     * 添加
     */
    @PostMapping("addClass")
    @Log(title = "添加班级",businessType = BusinessType.INSERT)
    public R addClass(@Validated  ClassDto classDto) {
        classDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return R.toAjax(this.classService.addClass(classDto));
    }

    /**
     * 修改
     */
    @PutMapping("updateClass")
    @Log(title = "修改科室",businessType = BusinessType.UPDATE)
    public R updateClass(@Validated @RequestBody ClassDto classDto) {
        classDto.setSimpleUser(ShiroSecurityUtils.getCurrentSimpleUser());
        return R.toAjax(this.classService.updateClass(classDto));
    }


    /**
     * 根据ID查询一个科室信息
     */
    @GetMapping("getClassById/{classId}")
    public R getClassById(@PathVariable @Validated @NotNull(message = "科室ID不能为空") Long classId) {
        return R.success(this.classService.getOne(classId));
    }

    /**
     * 删除
     */
    @DeleteMapping("deleteClassByIds/{classIds}")
    @Log(title = "删除科室",businessType = BusinessType.DELETE)
    public R deleteClassByIds(@PathVariable @Validated @NotEmpty(message = "要删除的ID不能为空") Long[] classIds) {
        return R.toAjax(this.classService.deleteClassByIds(classIds));
    }

    /**
     * 查询所有可用的科室
     */
    @GetMapping("selectAllClass")
    public R selectAllClass(){
        return R.success(this.classService.list());
    }

}
